package com.lcm.jnode.interceptor;

import java.util.List;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.lcm.jnode.model.Blog;
import com.lcm.jnode.utils.DateUtils;

/**
 * 侧边栏
 * @author L.cm
 * @date 2013-5-7 下午4:02:19
 */
public class SidebarInterceptor implements Interceptor {

    @Override
    public void intercept(ActionInvocation ai) {
        ai.invoke();
        // 热门话题
        List<Blog> topBlogs = Blog.dao.findHotList();
        for (Blog blog : topBlogs) {
            blog.set(Blog.UPDATE_TIME, DateUtils.formatCn(blog.getTimestamp(Blog.UPDATE_TIME)));
        }
        ai.getController().setAttr("topBlogs", topBlogs);
        // 最新博文
        List<Blog> lateBlogs = Blog.dao.findLateList();
        for (Blog blog : lateBlogs) {
            blog.set(Blog.UPDATE_TIME, DateUtils.formatCn(blog.getTimestamp(Blog.UPDATE_TIME)));
        }
        ai.getController().setAttr("lateBlogs", lateBlogs);
    }
}
